package kxfang.com.food.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import kxfang.com.food.R;
import kxfang.com.common.bean.TopListModel;
import kxfang.com.food.databinding.FoodAdapterLabelFlexBoxItemBinding;

/**
 * 自适应flexbox的adapter
 */
public class LabelFlexBoxAdapter extends BaseQuickAdapter<TopListModel, BaseViewHolder> {


    public LabelFlexBoxAdapter() {
        super(R.layout.food_adapter_label_flex_box_item);
    }

    @Override
    public int getItemCount() {
        if (getData().size() > 3) {
            return 3;
        } else
            return getData().size();
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, @Nullable TopListModel topListModel) {
        if (topListModel == null){
            return;
        }
        FoodAdapterLabelFlexBoxItemBinding binding = baseViewHolder.getBinding();
        if (binding != null){
            binding.setModel(topListModel);
        }
    }
}
